﻿//easymvc.js库逻辑扩展
//定义员工逻辑扩展（员工页面引用）

easymvc.extend('UserIndex', {

    //点击员工列表的行时执行
    onClickRow: function (index, row) {
        
    },

    //新增
    add: function (opty) { //新增员工信息
        var dialog;

        //定义参数
        var addUpdatePostUrl = "/api/User/Add";
        var gridId = "UserIndex";
        var formId = "FrmUserInfo_Dialog";

        var buttons = easymvc.getDefaultButtons();
        buttons[0].handler = function () {
            easymvc.submit({ dialog: dialog, form: formId, url: addUpdatePostUrl, grid: gridId });
        }

        dialog = easymvc.dialog({ url: '/dialog/useraddupdate', grid: '', width: 650, height: 450, buttons: buttons, title: '新增' });
    },

    //修改
    edit: function (opty) {
        var dialog;
        //定义参数
        var addUpdatePostUrl = "/api/User/Update";
        var gridId = "UserIndex";
        var formId = "FrmUserInfo_Dialog";

        var buttons = easymvc.getDefaultButtons();
        buttons[0].handler = function () {
            easymvc.submit({ dialog: dialog, form: formId, url: addUpdatePostUrl, grid: gridId });
        }

        var row = $("#" + gridId).datagrid("getSelected");

        dialog = easymvc.dialog({ url: '/dialog/useraddupdate?UserId=' + (row ? row.Id : ""), grid: gridId, width: 650, height: 450, buttons: buttons, title: '修改' });

        //if (dialog) {
        //    var row = $("#" + gridId).datagrid("getSelected");
        //    var form = easymvc.getForm(formId, dialog);

        //    form.form('load', row);
        //    form.find("#JoinOn").val(easymvc.GetCovDate(row.JoinOn, "yyyy-MM-dd"));
        //    form.find("#Birthday").val(easymvc.GetCovDate(row.Birthday, "yyyy-MM-dd"));
        //    form.find("#GraduatedOn").val(easymvc.GetCovDate(row.GraduatedOn, "yyyy-MM-dd"));
        //    form.find("#LeaveOn").val(easymvc.GetCovDate(row.LeaveOn, "yyyy-MM-dd"));

        //    form.find('#DepartmentId').combotree({
        //        url: "/api/department/index",
        //        parentField: 'ParentId',
        //        loadFilter: function (data) {
        //            if (data.IsSuccess) {
        //                return data.Data
        //            } else {
        //                return [];
        //            }
        //        },
        //    });
        //}
    },

    //删除
    delete: function (opty) {
        var postUrl = "/api/User/delete";        //删除后提交的url
        var gridId = "UserIndex";                //treegrid id
        var grid = $("#" + gridId);

        var row = grid.datagrid("getSelected");
        var url = "", id = "", name = "";
        if (row != null) {
            id = row.Id;
            name = row.LoginName;
        }

        easymvc.confirm({
            msg: '您确定要删除(员工:' + name + ')吗？<br/>注意：删除后不可恢复！', grid: gridId, callback: function () {
                easymvc.ajax({
                    url: postUrl,
                    data: { id: id },
                    grid: gridId
                });
            }
        });
    },

    //初始化
    init: function (dialog) {
        

    }

});
$(function () {
    easymvc.init();
})






